<?php
require_once("../../Config.php");
require_once("../../Class/ClassFunc.php");
require_once("../../Class/ClassMysql.php");
require_once("../../Class/ClassCheck.php");
require_once("../../Class/ClassResult.php");

//json头
header("Content-type: application/json");

if(isset($_GET["id"])) {
    if(!Check::isNum($_GET["id"])||(int)$_GET["id"]<=0){
      exit(Result::jsonReturn(1, "参数有误"));
    }
    $db = new Db();
    $id = (int)$_GET["id"];
    $sql = "SELECT id,title,`text`,slug,type,created_time,updated_time FROM qilian_contents WHERE type=0 AND id={$id}";
    $res = $db->getOne($sql);
    exit(Result::jsonReturn(0, "查询成功", $res));
}elseif(isset($_GET["slug"])) {
  if(!Check::isSlug($_GET["slug"])) {
    exit(Result::jsonReturn(1, "参数有误"));
  }
  $db = new Db();
  $slug = $_GET["slug"];
  $sql = "SELECT id,title,`text`,slug,type,created_time,updated_time FROM qilian_contents WHERE type=0 AND slug='{$slug}'";
  $res = $db->getOne($sql);
  exit(Result::jsonReturn(0, "查询成功", $res));
}else {
    exit(Result::jsonReturn(1, "缺少参数"));
}

?>